using System;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace GameCore.UI
{
    public class AreaTagUI : MonoBehaviour, IPointerDownHandler
    {
        public Image image;
        public AdventureUI ui;
        public AreaConfig areaConfig;
        public TMP_Text txt_Name;
        public TMP_Text txt_Steps;
        
        public GameObject selectionIndicator;
        
        private void Start()
        {
            txt_Name.text = areaConfig.areaID.id;
            txt_Steps.text = areaConfig.steps.ToString();
        }

        private void OnValidate()
        {
            image ??= GetComponent<Image>();
            image.sprite = areaConfig.activeSprite;
            txt_Name.text = areaConfig.areaID.id;
            txt_Steps.text = areaConfig.steps.ToString();
        }

        public void SetTagActive()
        {
            image.sprite = areaConfig.activeSprite;
        }

        public void SetTagInactive()
        {
            image.sprite = areaConfig.inactiveSprite;
        }

        public void Select()
        {
            selectionIndicator.SetActive(true);
        }

        public void Deselect()
        {
            selectionIndicator.SetActive(false);
        }
        
        public void OnPointerDown(PointerEventData eventData)
        {
            ui.SetSelectedArea(this);
        }
    }
}